<template>
	<!--公司信息	-->
	<div>
		<FormPanel ref="FormPanel" :list="initForm" :cols="2" :formType="formType" :labelWidth="180" :isSubmitBtn="false" @formChange="formChangeHandle" class="mtop" />
	</div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import * as types from '@/api/cms-api/origin/originInfo/types';

import vm from './bridge';

export default {
	mixins: [dictionary],
	model: {
		prop: 'pdata', //为了和v-model默认的value区分，将prop改为自定义的名称
		event: 'click' //为了和v-model默认的input区分，将event改为click
	},
	props: {
		pdata: {
			type: Object,
			default: () => ({})
		},
		formType: {
			type: String,
			required: true
		}
	},
	data() {
		return {
			initForm: this.initFormFun()
		};
	},
	mounted() {
		//注册经销商类型变化时触发的事件
		//在审核时，给此页面的类型为只读，但是基本信息（infoBase可以编辑，会显示会触发事件，事件会触发禁用取消，覆盖整个表单的类型（表单类型为show，但是依旧可以输入，（部分）））
		if (this.formType != 'show') {
			vm.$on('changeDealerType', this.changeDealerType);
		}
	},
	methods: {
		//初始化数据
		init(data) {
			this.initForm.forEach(x => {
				x.initialValue = this.pdata[x.fieldName];
			});
		},
		formChangeHandle(val) {
			this.pdata = Object.assign(this.pdata, val);
			//传递数据到父组件里
			this.$emit('click', this.pdata);
			//触发外部的事件，以标志着本表单已经准备完毕
			this.$emit('formchange', this.pdata);
		},
		saveDialog() {
			this.$refs.FormPanel.SUBMIT_FORM();
		},
		//经销商类型变更时
		changeDealerType(value) {
			if (types.DEALER_INFO_DEALER_TYPE_BIG_CUSTOMER === value) {
				this.companyEnabled();
			} else {
				this.companyDisabled();
			}
			// this.refreshFormRules();
		},
		//禁用公司信息部分
		companyDisabled() {
			vm.companyDisabled(this.initForm, false);
			vm.clearValidate(this.$refs.FormPanel);
		},
		//启用公司信息部分
		companyEnabled() {
			vm.companyEnabled(this.initForm, false);
			vm.clearValidate(this.$refs.FormPanel);
		},
		//刷新验证内容
		// refreshFormRules(){
		// 	vm.refreshFormRules(this,this.$refs.FormPanel,this.initForm);
		// },
		//搜索数据
		initFormFun() {
			return [
				{ type: 'INPUT', label: '公司名称', fieldName: 'companyName', initialValue: '', placeholder: '', maxlength: 300 },
				{ type: 'INPUT', label: '法定代表人', fieldName: 'representative', initialValue: '', maxlength: 30, placeholder: '' },
				{ type: 'INPUT', label: '销售邮箱', fieldName: 'salesEmail', initialValue: '', placeholder: '', maxlength: 60, disabled: false },
				{ type: 'INPUT', label: '销售热线', fieldName: 'salesLine', initialValue: '', placeholder: '', maxlength: 30, disabled: false },
				{ type: 'INPUT', label: '售后服务热线', fieldName: 'serviceLine', initialValue: '', placeholder: '', maxlength: 30, disabled: false },
				{ type: 'INPUT', label: '售后邮箱', fieldName: 'serviceEmail', initialValue: '', placeholder: '', maxlength: 60, disabled: false },
				// {type:'INPUT',label:'前台座机',fieldName:'frontHotline',initialValue:'',placeholder:'',maxlength:30,disabled:false},
				{ type: 'INPUT', label: '24小时服务电话', fieldName: 'hotLine', initialValue: '', placeholder: '', maxlength: 30, disabled: false },
				{ type: 'DATE', label: '成立日期', fieldName: 'establishmentDate', dateType: 'date', valueFormat: 'yyyy-MM-dd', initialValue: '', placeholder: '', style: { width: '100%' } },
				{ type: 'INPUT', label: '纳税人识别号', fieldName: 'taxpayerIdentityNumber', initialValue: '', maxlength: 20, placeholder: '' },
				{ type: 'INPUT', label: '登记机关', fieldName: 'registerGov', selfCols: 2, initialValue: '', placeholder: '', maxlength: 300 },
				{ type: 'DATE', label: '营业执照有效期', valueFormat: 'yyyy-MM-dd', fieldName: 'businessTerm', initialValue: '', maxlength: 100, placeholder: '' },
				{ type: 'TEXT_AREA', label: '营业执照地址', fieldName: 'registerAddress', selfCols: 2, rows: 2, initialValue: '', placeholder: '', maxlength: 240 },
				{ type: 'INPUT',label:'道路运输经营许可证',fieldName:'roadTransportationLicense',initialValue:'',placeholder:'',maxlength:100,disabled:false},
				{ type: 'SELECT',label:'维修资质类别',fieldName:'maintenanceCategory',placeholder:'',initialValue:'',disabled:false,itemList:this.createDictList('2587'),},
					{type: 'UPLOAD_FILE',label: '许可证附件',fieldName: 'licenceEnclosureList',initialValue: [],
						selfCols:2,
						upload: {
							actionUrl: '/api/file/oss/upload', //上传的地址
							limit: 99, //上传数量
							fileTypes:[
								'jpg','jpeg','png','gif',
								'doc','docx','xls','xlsx','ppt','pptx','txt','pdf',
								'rar','zip',
							],
						},
					},

				{
					type: 'UPLOAD_FILE',
					label: '营业执照扫描件',
					selfCols: 2,
					fieldName: 'businessLicenseEnclosureList',
					initialValue: [],
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
					}
				},
				{
					type: 'UPLOAD_FILE',
					label: '法定代表人附件',
					selfCols: 2,
					fieldName: 'legalRepresentativeEnclosureList',
					initialValue: [],
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
					}
				},
				{
					type: 'UPLOAD_FILE',
					label: '首笔提车款附件',
					selfCols: 2,
					fieldName: 'firstPaymentEnclosureList',
					initialValue: [],
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						limit: 99, //上传数量
						fileTypes: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'pdf', 'rar', 'zip']
					}
				}
			];
		}
	}
};
</script>
